(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 12.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       158,          7]
NotebookDataLength[     48642,       1279]
NotebookOptionsPosition[     46672,       1246]
NotebookOutlinePosition[     47026,       1262]
CellTagsIndexPosition[     46983,       1259]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
 RowBox[{"Clear", "[", "\"\<Global'*\>\"", "]"}]], "Input",
 CellChangeTimes->{{3.8517547222481976`*^9, 3.851754772777483*^9}},
 CellLabel->"In[20]:=",ExpressionUUID->"6814b69d-8fee-4b41-9bc4-e7c2489429c8"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"SetDirectory", "[", 
  RowBox[{"NotebookDirectory", "[", "]"}], "]"}]], "Input",
 CellChangeTimes->{{3.8517547790262747`*^9, 3.8517547933973308`*^9}},
 CellLabel->"In[21]:=",ExpressionUUID->"64aafcbe-cf03-4ab2-ba0a-3e637cc7e450"],

Cell[BoxData["\<\"C:\\\\Users\\\\hzc88\\\\Desktop\\\\DataAnalysis\\\\func\"\>\
"], "Output",
 CellChangeTimes->{
  3.851755794234046*^9, 3.8518330893266015`*^9, {3.851833185206566*^9, 
   3.8518331955687637`*^9}, 3.8518334892903433`*^9, 3.8518348052729826`*^9, 
   3.8518349370320716`*^9, 3.8518469497104063`*^9, 3.8518470357209573`*^9, 
   3.8518470764187484`*^9, 3.85184717635036*^9, 3.851847315812583*^9, 
   3.851847997800212*^9, 3.8518481071420765`*^9, 3.85184861435851*^9, 
   3.8518487065576506`*^9, 3.851848742749401*^9, 3.8518487868577104`*^9, 
   3.8518488762228603`*^9, 3.851848919305575*^9, 3.85184898700333*^9, 
   3.851849282957446*^9, 3.8541650307600794`*^9, 3.8541932731254683`*^9, 
   3.8541942241504993`*^9, {3.8541944178907785`*^9, 3.8541944192340813`*^9}, 
   3.8541954927347965`*^9, 3.8543943930315895`*^9, 3.8575386808667593`*^9, 
   3.8575484996233215`*^9, 3.8575492583767223`*^9, 3.8586726842678804`*^9, 
   3.8629030686970205`*^9, 3.862904964033092*^9, 3.862905262890057*^9, 
   3.8629053363487*^9, 3.8853713650394387`*^9},
 CellLabel->"Out[21]=",ExpressionUUID->"23e4677b-24be-4d4a-a69e-4738ba474037"]
}, Open  ]],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"Unitarization", "[", "A11_", "]"}], ":=", 
   RowBox[{"Block", "[", 
    RowBox[{
     RowBox[{"{", "\[IndentingNewLine]", 
      RowBox[{
      "s1", ",", "v1", ",", "d1", ",", "\[IndentingNewLine]", "c1", ",", 
       "A12", ",", "s12", ",", "v12", ",", "d12", ",", "d32", ",", 
       "\[IndentingNewLine]", "a11", ",", "a12", ",", "a13", ",", "a14", ",", 
       "AF"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{
       RowBox[{"{", 
        RowBox[{"s1", ",", "v1", ",", "d1"}], "}"}], "=", 
       RowBox[{"SingularValueDecomposition", "[", "A11", "]"}]}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{"c1", "=", 
       RowBox[{"Max", "[", "v1", "]"}]}], ";", "\[IndentingNewLine]", 
      RowBox[{"A12", "=", 
       RowBox[{"A11", "/", "c1"}]}], ";", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{"s12", ",", "v12", ",", "d12"}], "}"}], "=", 
       RowBox[{"SingularValueDecomposition", "[", "A12", "]"}]}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{"d32", "=", 
       RowBox[{"ConjugateTranspose", "[", "d12", "]"}]}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{"a11", "=", 
       RowBox[{"s12", ".", 
        RowBox[{"Sqrt", "[", 
         RowBox[{
          RowBox[{"DiagonalMatrix", "[", 
           RowBox[{"ConstantArray", "[", 
            RowBox[{"1", ",", 
             RowBox[{
              RowBox[{"Dimensions", "[", 
               RowBox[{"v12", ".", 
                RowBox[{"Transpose", "[", "v12", "]"}]}], "]"}], "[", 
              RowBox[{"[", "1", "]"}], "]"}]}], "]"}], "]"}], "-", 
          RowBox[{"v12", ".", 
           RowBox[{"Transpose", "[", "v12", "]"}]}]}], "]"}], ".", "s12"}]}], 
      ";", "\[IndentingNewLine]", 
      RowBox[{"a12", "=", 
       RowBox[{"d32", ".", 
        RowBox[{"Sqrt", "[", 
         RowBox[{
          RowBox[{"DiagonalMatrix", "[", 
           RowBox[{"ConstantArray", "[", 
            RowBox[{"1", ",", 
             RowBox[{
              RowBox[{"Dimensions", "[", 
               RowBox[{
                RowBox[{"Transpose", "[", "v12", "]"}], ".", "v12"}], "]"}], 
              "[", 
              RowBox[{"[", "1", "]"}], "]"}]}], "]"}], "]"}], "-", 
          RowBox[{
           RowBox[{"Transpose", "[", "v12", "]"}], ".", "v12"}]}], "]"}], ".",
         "d32"}]}], ";", "\[IndentingNewLine]", 
      RowBox[{"a14", "=", 
       RowBox[{"-", 
        RowBox[{"d32", ".", 
         RowBox[{"Transpose", "[", "v12", "]"}], ".", "s12"}]}]}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{"AF", "=", 
       RowBox[{"ArrayFlatten", "[", 
        RowBox[{"{", 
         RowBox[{
          RowBox[{"{", 
           RowBox[{"A12", ",", "a11"}], "}"}], ",", 
          RowBox[{"{", 
           RowBox[{"a12", ",", "a14"}], "}"}]}], "}"}], "]"}]}], ";", 
      "\[IndentingNewLine]", "AF"}]}], "\[IndentingNewLine]", "]"}]}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"F1", "[", 
   RowBox[{"theta_", ",", "phi_"}], "]"}], ":=", 
  RowBox[{"{", 
   RowBox[{
    RowBox[{"Cos", "[", 
     RowBox[{"theta", "/", "2"}], "]"}], ",", 
    RowBox[{
     RowBox[{"Exp", "[", 
      RowBox[{"I", " ", "phi"}], "]"}], " ", 
     RowBox[{"Sin", "[", 
      RowBox[{"theta", "/", "2"}], "]"}]}]}], "}"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"P1", "[", 
   RowBox[{"theta_", ",", "phi_"}], "]"}], ":=", 
  RowBox[{"Flatten", "[", 
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{
      RowBox[{
       RowBox[{"F1", "[", 
        RowBox[{
         RowBox[{"Pi", "/", "2"}], ",", 
         RowBox[{"Pi", "/", "2"}]}], "]"}], "[", 
       RowBox[{"[", "x", "]"}], "]"}], "*", 
      RowBox[{"F1", "[", 
       RowBox[{"theta", ",", "phi"}], "]"}]}], ",", 
     RowBox[{"{", 
      RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], 
   "]"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"P2", "[", 
   RowBox[{"theta_", ",", "phi_"}], "]"}], ":=", 
  RowBox[{"Flatten", "[", 
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{
      RowBox[{
       RowBox[{"F1", "[", 
        RowBox[{
         RowBox[{"Pi", "/", "2"}], ",", 
         RowBox[{"3", 
          RowBox[{"Pi", "/", "2"}]}]}], "]"}], "[", 
       RowBox[{"[", "x", "]"}], "]"}], "*", 
      RowBox[{"F1", "[", 
       RowBox[{"theta", ",", "phi"}], "]"}]}], ",", 
     RowBox[{"{", 
      RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}]}], "Input",
 CellChangeTimes->{{3.851754544103668*^9, 3.8517545447086906`*^9}, {
  3.851754716800397*^9, 3.8517547194308743`*^9}, {3.851833167876814*^9, 
  3.8518331745981646`*^9}},
 CellLabel->"In[22]:=",ExpressionUUID->"8fc10523-3fdb-442c-bdee-c18c75a3e2b0"],

Cell[BoxData[
 RowBox[{
  RowBox[{"P3", "[", 
   RowBox[{"theta_", ",", "phi_"}], "]"}], ":=", 
  RowBox[{"Flatten", "[", 
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{
      RowBox[{
       RowBox[{"F1", "[", 
        RowBox[{"theta", ",", "phi"}], "]"}], "[", 
       RowBox[{"[", "x", "]"}], "]"}], "*", 
      RowBox[{"F1", "[", 
       RowBox[{
        RowBox[{"Pi", "/", "2"}], ",", 
        RowBox[{"Pi", "/", "2"}]}], "]"}]}], ",", 
     RowBox[{"{", 
      RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}]], "Input",
 CellLabel->"In[26]:=",ExpressionUUID->"dda2564d-b9b3-480a-bbc7-4a2d75d0a1c5"],

Cell[BoxData[
 RowBox[{
  RowBox[{"P4", "[", 
   RowBox[{"theta_", ",", "phi_"}], "]"}], ":=", 
  RowBox[{"Flatten", "[", 
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{
      RowBox[{
       RowBox[{"F1", "[", 
        RowBox[{"theta", ",", "phi"}], "]"}], "[", 
       RowBox[{"[", "x", "]"}], "]"}], "*", 
      RowBox[{"F1", "[", 
       RowBox[{
        RowBox[{"Pi", "/", "2"}], ",", 
        RowBox[{"3", 
         RowBox[{"Pi", "/", "2"}]}]}], "]"}]}], ",", 
     RowBox[{"{", 
      RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}]], "Input",
 CellLabel->"In[27]:=",ExpressionUUID->"d350f6dc-dea1-43c6-86d7-a7bfc3331caa"],

Cell[BoxData[
 RowBox[{
  RowBox[{"Instat1", "=", 
   RowBox[{"Flatten", "[", 
    RowBox[{"Table", "[", 
     RowBox[{
      RowBox[{
       RowBox[{
        RowBox[{"F1", "[", 
         RowBox[{
          RowBox[{"Pi", "/", "2"}], ",", 
          RowBox[{"3", 
           RowBox[{"Pi", "/", "2"}]}]}], "]"}], "[", 
        RowBox[{"[", "x", "]"}], "]"}], "*", 
       RowBox[{"F1", "[", 
        RowBox[{
         RowBox[{"Pi", "/", "2"}], ",", 
         RowBox[{"3", 
          RowBox[{"Pi", "/", "2"}]}]}], "]"}]}], ",", 
      RowBox[{"{", 
       RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], 
  ";"}]], "Input",
 CellLabel->"In[28]:=",ExpressionUUID->"29aa4b86-7d5c-4e88-9ce5-9739ee71a7c5"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Instant", "[", 
    RowBox[{"t_", ",", "p_"}], "]"}], ":=", 
   RowBox[{"Flatten", "[", 
    RowBox[{"Table", "[", 
     RowBox[{
      RowBox[{
       RowBox[{
        RowBox[{"F1", "[", 
         RowBox[{
          RowBox[{"Pi", "/", "2"}], ",", 
          RowBox[{"Pi", "/", "2"}]}], "]"}], "[", 
        RowBox[{"[", "x", "]"}], "]"}], "*", 
       RowBox[{"P1", "[", 
        RowBox[{"t", ",", "p"}], "]"}]}], ",", 
      RowBox[{"{", 
       RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], 
  ";"}]], "Input",
 CellLabel->"In[29]:=",ExpressionUUID->"e9382540-8936-4a17-8098-0168a221185d"],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"Instant4", "[", 
    RowBox[{"t_", ",", "p_"}], "]"}], ":=", 
   RowBox[{"Flatten", "[", 
    RowBox[{"Table", "[", 
     RowBox[{
      RowBox[{
       RowBox[{
        RowBox[{"F1", "[", 
         RowBox[{"t", ",", "p"}], "]"}], "[", 
        RowBox[{"[", "x", "]"}], "]"}], "*", 
       RowBox[{"P1", "[", 
        RowBox[{
         RowBox[{"Pi", "/", "2"}], ",", 
         RowBox[{"Pi", "/", "2"}]}], "]"}]}], ",", 
      RowBox[{"{", 
       RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"Instant5", "[", 
    RowBox[{"t_", ",", "p_"}], "]"}], ":=", 
   RowBox[{"Flatten", "[", 
    RowBox[{"Table", "[", 
     RowBox[{
      RowBox[{
       RowBox[{
        RowBox[{"F1", "[", 
         RowBox[{"t", ",", "p"}], "]"}], "[", 
        RowBox[{"[", "x", "]"}], "]"}], "*", 
       RowBox[{"P3", "[", 
        RowBox[{
         RowBox[{"Pi", "/", "2"}], ",", 
         RowBox[{"Pi", "/", "2"}]}], "]"}]}], ",", 
      RowBox[{"{", 
       RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], 
  ";"}]}], "Input",
 CellChangeTimes->{{3.8629028394713573`*^9, 3.8629028398071856`*^9}},
 CellLabel->"In[30]:=",ExpressionUUID->"cbbc6a14-6179-4733-9593-34b1871680c6"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"Instat2", "=", 
   RowBox[{"Flatten", "[", 
    RowBox[{"Table", "[", 
     RowBox[{
      RowBox[{
       RowBox[{
        RowBox[{"F1", "[", 
         RowBox[{
          RowBox[{"Pi", "/", "2"}], ",", 
          RowBox[{"Pi", "/", "2"}]}], "]"}], "[", 
        RowBox[{"[", "x", "]"}], "]"}], "*", 
       RowBox[{"F1", "[", 
        RowBox[{
         RowBox[{"Pi", "/", "2"}], ",", 
         RowBox[{"Pi", "/", "2"}]}], "]"}]}], ",", 
      RowBox[{"{", 
       RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Instat3", "=", 
   RowBox[{"Flatten", "[", 
    RowBox[{"Table", "[", 
     RowBox[{
      RowBox[{
       RowBox[{
        RowBox[{"F1", "[", 
         RowBox[{
          RowBox[{"Pi", "/", "2"}], ",", 
          RowBox[{"Pi", "/", "2"}]}], "]"}], "[", 
        RowBox[{"[", "x", "]"}], "]"}], "*", "Instat2"}], ",", 
      RowBox[{"{", 
       RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], 
  ";"}]}], "Input",
 CellLabel->"In[32]:=",ExpressionUUID->"c0a69fe8-9e94-4b05-9eee-3404b29bb04b"],

Cell[BoxData[
 RowBox[{
  RowBox[{"Contourtest", "[", 
   RowBox[{"loopk_", ",", "J_"}], "]"}], ":=", 
  RowBox[{"Block", "[", 
   RowBox[{
    RowBox[{"{", "\[IndentingNewLine]", 
     RowBox[{"Instat1", ",", "\[IndentingNewLine]", "Instat"}], 
     "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"Instat1", "=", 
      RowBox[{"Flatten", "[", 
       RowBox[{"Table", "[", 
        RowBox[{
         RowBox[{
          RowBox[{
           RowBox[{"F1", "[", 
            RowBox[{
             RowBox[{"Pi", "/", "2"}], ",", 
             RowBox[{"Pi", "/", "2"}]}], "]"}], "[", 
           RowBox[{"[", "x", "]"}], "]"}], "*", 
          RowBox[{"F1", "[", 
           RowBox[{
            RowBox[{"Pi", "/", "2"}], ",", 
            RowBox[{"Pi", "/", "2"}]}], "]"}]}], ",", 
         RowBox[{"{", 
          RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"Instat", "=", 
      RowBox[{"Flatten", "[", 
       RowBox[{"Table", "[", 
        RowBox[{
         RowBox[{
          RowBox[{
           RowBox[{"F1", "[", 
            RowBox[{
             RowBox[{"Pi", "/", "2"}], ",", 
             RowBox[{"Pi", "/", "2"}]}], "]"}], "[", 
           RowBox[{"[", "x", "]"}], "]"}], "*", "Instat1"}], ",", 
         RowBox[{"{", 
          RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"{", 
      RowBox[{
       RowBox[{"ContourPlot", "[", 
        RowBox[{
         RowBox[{"Abs", "[", 
          RowBox[{
           RowBox[{"Conjugate", "[", 
            RowBox[{"P2", "[", 
             RowBox[{"x", ",", "y"}], "]"}], "]"}], ".", 
           RowBox[{"(", 
            RowBox[{"loopk", "/", "J"}], ")"}], ".", "Instat"}], "]"}], ",", 
         RowBox[{"{", 
          RowBox[{"x", ",", "0", ",", "Pi"}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{"y", ",", "0", ",", 
           RowBox[{"2", "Pi"}]}], "}"}], ",", 
         RowBox[{"Contours", "\[Rule]", "15"}], ",", 
         RowBox[{"ColorFunction", "\[Rule]", 
          RowBox[{"ColorData", "[", 
           RowBox[{"{", 
            RowBox[{"\"\<SandyTerrain\>\"", ",", 
             RowBox[{"{", 
              RowBox[{"0", ",", "0.6"}], "}"}]}], "}"}], "]"}]}], ",", 
         RowBox[{"ColorFunctionScaling", "\[Rule]", "False"}], ",", 
         RowBox[{"PlotLegends", "\[Rule]", 
          RowBox[{"BarLegend", "[", 
           RowBox[{
            RowBox[{"{", 
             RowBox[{"Automatic", ",", 
              RowBox[{"{", 
               RowBox[{"0", ",", "0.6"}], "}"}]}], "}"}], ",", 
            RowBox[{"{", 
             RowBox[{"Automatic", ",", "20"}], "}"}], ",", 
            RowBox[{"LegendMarkerSize", "\[Rule]", "350"}], ",", 
            RowBox[{"LegendFunction", "\[Rule]", "\"\<Frame\>\""}], ",", 
            RowBox[{"LegendMargins", "\[Rule]", "5"}], ",", 
            RowBox[{"LegendLabel", "\[Rule]", "\"\<Amplitude\>\""}]}], 
           "]"}]}], ",", 
         RowBox[{"FrameLabel", "->", 
          RowBox[{"{", 
           RowBox[{
            RowBox[{"Style", "[", 
             RowBox[{"\"\<\[Phi]\>\"", ",", "Large"}], "]"}], ",", 
            RowBox[{"Style", "[", 
             RowBox[{"\"\<\[CapitalTheta]\>\"", ",", "Large"}], "]"}]}], 
           "}"}]}], ",", 
         RowBox[{"RotateLabel", "\[Rule]", "False"}], ",", 
         RowBox[{"PlotLegends", "\[Rule]", "Automatic"}], ",", 
         RowBox[{"Contours", "\[Rule]", "100"}], ",", 
         RowBox[{"GridLines", "\[Rule]", 
          RowBox[{"{", 
           RowBox[{
            RowBox[{"Range", "[", 
             RowBox[{"0", ",", "Pi", ",", 
              RowBox[{"Pi", "/", "4"}]}], "]"}], ",", " ", 
            RowBox[{"Range", "[", 
             RowBox[{"0", ",", 
              RowBox[{"2", "Pi"}], ",", 
              RowBox[{"Pi", "/", "4"}]}], "]"}]}], "}"}]}], ",", 
         RowBox[{"FrameStyle", "\[Rule]", 
          RowBox[{"Directive", "[", 
           RowBox[{"FontSize", "\[Rule]", "15"}], "]"}]}], ",", 
         RowBox[{"FrameTicks", "\[Rule]", 
          RowBox[{"{", 
           RowBox[{
            RowBox[{"{", 
             RowBox[{
              RowBox[{"{", 
               RowBox[{"0", ",", 
                RowBox[{"Pi", "/", "2"}], ",", "Pi", ",", 
                RowBox[{"3", 
                 RowBox[{"Pi", "/", "2"}]}], ",", 
                RowBox[{"2", "Pi"}]}], "}"}], ",", "None"}], "}"}], ",", 
            RowBox[{"{", 
             RowBox[{
              RowBox[{"{", 
               RowBox[{"0", ",", 
                RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], ",", "None"}], 
             "}"}]}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", 
       RowBox[{"FindMaximum", "[", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{
           RowBox[{"Abs", "[", 
            RowBox[{
             RowBox[{"Conjugate", "[", 
              RowBox[{
               RowBox[{"P2", "[", 
                RowBox[{"x1", ",", "y1"}], "]"}], ".", 
               RowBox[{"(", 
                RowBox[{"loopk", "/", "J"}], ")"}]}], "]"}], ".", "Instat"}], 
            "]"}], ",", 
           RowBox[{
            RowBox[{"x1", "\[GreaterEqual]", "0"}], "&&", 
            RowBox[{"y1", "\[GreaterEqual]", "0"}], "&&", 
            RowBox[{"x1", "\[LessEqual]", " ", "Pi"}], "&&", 
            RowBox[{"y1", "\[LessEqual]", 
             RowBox[{"2", "Pi"}]}]}]}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"x1", ",", 
             RowBox[{"Pi", "/", "2"}]}], "}"}], ",", 
           RowBox[{"{", 
            RowBox[{"y1", ",", 
             RowBox[{"3", 
              RowBox[{"Pi", "/", "2"}]}]}], "}"}]}], "}"}]}], "]"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{"FindMinimum", "[", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{
           RowBox[{"Abs", "[", 
            RowBox[{
             RowBox[{"Conjugate", "[", 
              RowBox[{
               RowBox[{"P2", "[", 
                RowBox[{"x1", ",", "y1"}], "]"}], ".", 
               RowBox[{"(", 
                RowBox[{"loopk", "/", "J"}], ")"}]}], "]"}], ".", "Instat"}], 
            "]"}], ",", 
           RowBox[{
            RowBox[{"x1", "\[GreaterEqual]", "0"}], "&&", 
            RowBox[{"y1", "\[GreaterEqual]", "0"}], "&&", 
            RowBox[{"x1", "\[LessEqual]", " ", "Pi"}], "&&", 
            RowBox[{"y1", "\[LessEqual]", 
             RowBox[{"2", "Pi"}]}]}]}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"x1", ",", 
             RowBox[{"Pi", "/", "2"}]}], "}"}], ",", 
           RowBox[{"{", 
            RowBox[{"y1", ",", 
             RowBox[{"Pi", "/", "2"}]}], "}"}]}], "}"}]}], "]"}]}], 
      "\[IndentingNewLine]", "}"}]}]}], "\[IndentingNewLine]", 
   "]"}]}]], "Input",
 CellChangeTimes->{{3.85183335518009*^9, 3.8518334232201867`*^9}, {
   3.851834757490964*^9, 3.8518347950886307`*^9}, {3.85183491194328*^9, 
   3.8518349254705515`*^9}, 3.8518470316605406`*^9, {3.8518470684110794`*^9, 
   3.851847073382037*^9}, {3.8518471698682723`*^9, 3.851847174974222*^9}, {
   3.851847300416551*^9, 3.851847311366324*^9}, {3.851847974148595*^9, 
   3.851847992716032*^9}, {3.851848099104132*^9, 3.851848101792386*^9}, {
   3.85184861185856*^9, 3.8518486122415843`*^9}, {3.8518486994081297`*^9, 
   3.851848703287427*^9}, {3.851848738824705*^9, 3.8518487413056507`*^9}, {
   3.851848869927871*^9, 3.851848872373234*^9}, {3.8518489822960806`*^9, 
   3.851848984763815*^9}, {3.851849276453921*^9, 3.8518492807385073`*^9}, {
   3.854194178027527*^9, 3.8541942197215004`*^9}, {3.8541944104180937`*^9, 
   3.854194415935337*^9}, {3.8541954192874513`*^9, 3.854195434004446*^9}, {
   3.8543943773690577`*^9, 3.854394380728815*^9}, {3.8575386552913847`*^9, 
   3.85753867788671*^9}, 3.857548495370171*^9, {3.8575492533402414`*^9, 
   3.8575492537428713`*^9}, 3.858672680221964*^9},
 CellLabel->"In[34]:=",ExpressionUUID->"fc1813e4-6d99-41a8-a1cc-919b81c5a1c8"],

Cell[BoxData[
 RowBox[{
  RowBox[{"Contourtest2", "[", "loopk_", "]"}], ":=", 
  RowBox[{"{", 
   RowBox[{
    RowBox[{"ContourPlot", "[", 
     RowBox[{
      RowBox[{"Abs", "[", 
       RowBox[{
        RowBox[{"Conjugate", "[", "Instat1", "]"}], ".", 
        RowBox[{"(", "loopk", ")"}], ".", 
        RowBox[{"Instant", "[", 
         RowBox[{"x", ",", "y"}], "]"}]}], "]"}], ",", 
      RowBox[{"{", 
       RowBox[{"x", ",", "0", ",", "Pi"}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{"y", ",", "0", ",", 
        RowBox[{"2", "Pi"}]}], "}"}], ",", 
      RowBox[{"Contours", "\[Rule]", "15"}], ",", 
      RowBox[{"ColorFunction", "\[Rule]", 
       RowBox[{"ColorData", "[", 
        RowBox[{"{", 
         RowBox[{"\"\<SandyTerrain\>\"", ",", 
          RowBox[{"{", 
           RowBox[{"0", ",", "0.6"}], "}"}]}], "}"}], "]"}]}], ",", 
      RowBox[{"ColorFunctionScaling", "\[Rule]", "False"}], ",", 
      RowBox[{"PlotLegends", "\[Rule]", 
       RowBox[{"BarLegend", "[", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{"Automatic", ",", 
           RowBox[{"{", 
            RowBox[{"0", ",", "0.6"}], "}"}]}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{"Automatic", ",", "20"}], "}"}], ",", 
         RowBox[{"LegendMarkerSize", "\[Rule]", "350"}], ",", 
         RowBox[{"LegendFunction", "\[Rule]", "\"\<Frame\>\""}], ",", 
         RowBox[{"LegendMargins", "\[Rule]", "5"}], ",", 
         RowBox[{"LegendLabel", "\[Rule]", "\"\<Amplitude\>\""}]}], "]"}]}], 
      ",", 
      RowBox[{"FrameLabel", "->", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"Style", "[", 
          RowBox[{"\"\<\[Phi]\>\"", ",", "Large"}], "]"}], ",", 
         RowBox[{"Style", "[", 
          RowBox[{"\"\<\[CapitalTheta]\>\"", ",", "Large"}], "]"}]}], "}"}]}],
       ",", 
      RowBox[{"RotateLabel", "\[Rule]", "False"}], ",", 
      RowBox[{"PlotLegends", "\[Rule]", "Automatic"}], ",", 
      RowBox[{"Contours", "\[Rule]", "100"}], ",", 
      RowBox[{"GridLines", "\[Rule]", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"Range", "[", 
          RowBox[{"0", ",", "Pi", ",", 
           RowBox[{"Pi", "/", "4"}]}], "]"}], ",", " ", 
         RowBox[{"Range", "[", 
          RowBox[{"0", ",", 
           RowBox[{"2", "Pi"}], ",", 
           RowBox[{"Pi", "/", "4"}]}], "]"}]}], "}"}]}], ",", 
      RowBox[{"FrameStyle", "\[Rule]", 
       RowBox[{"Directive", "[", 
        RowBox[{"FontSize", "\[Rule]", "15"}], "]"}]}], ",", 
      RowBox[{"FrameTicks", "\[Rule]", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"0", ",", 
             RowBox[{"Pi", "/", "2"}], ",", "Pi", ",", 
             RowBox[{"3", 
              RowBox[{"Pi", "/", "2"}]}], ",", 
             RowBox[{"2", "Pi"}]}], "}"}], ",", "None"}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"0", ",", 
             RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], ",", "None"}], 
          "}"}]}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", 
    RowBox[{"FindMaximum", "[", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{
        RowBox[{"Abs", "[", 
         RowBox[{
          RowBox[{"Conjugate", "[", "Instat1", "]"}], ".", 
          RowBox[{"(", "loopk", ")"}], ".", 
          RowBox[{"Instant", "[", 
           RowBox[{"x1", ",", "y1"}], "]"}]}], "]"}], ",", 
        RowBox[{
         RowBox[{"x1", "\[GreaterEqual]", "0"}], "&&", 
         RowBox[{"y1", "\[GreaterEqual]", "0"}], "&&", 
         RowBox[{"x1", "\[LessEqual]", " ", "Pi"}], "&&", 
         RowBox[{"y1", "\[LessEqual]", 
          RowBox[{"2", "Pi"}]}]}]}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"x1", ",", 
          RowBox[{"Pi", "/", "2"}]}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"y1", ",", 
          RowBox[{"Pi", "/", "2"}]}], "}"}]}], "}"}]}], "]"}], ",", 
    "\[IndentingNewLine]", 
    RowBox[{"FindMinimum", "[", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{
        RowBox[{"Abs", "[", 
         RowBox[{
          RowBox[{"Conjugate", "[", "Instat1", "]"}], ".", 
          RowBox[{"(", "loopk", ")"}], ".", 
          RowBox[{"Instant", "[", 
           RowBox[{"x1", ",", "y1"}], "]"}]}], "]"}], ",", 
        RowBox[{
         RowBox[{"x1", "\[GreaterEqual]", "0"}], "&&", 
         RowBox[{"y1", "\[GreaterEqual]", "0"}], "&&", 
         RowBox[{"x1", "\[LessEqual]", " ", "Pi"}], "&&", 
         RowBox[{"y1", "\[LessEqual]", 
          RowBox[{"2", "Pi"}]}]}]}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"x1", ",", 
          RowBox[{"Pi", "/", "2"}]}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"y1", ",", 
          RowBox[{"3", 
           RowBox[{"Pi", "/", "2"}]}]}], "}"}]}], "}"}]}], "]"}]}], 
   "}"}]}]], "Input",
 CellLabel->"In[35]:=",ExpressionUUID->"973d8df8-bc65-4995-aa75-c3864a5e86c3"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Contourtest3", "[", "loopk_", "]"}], ":=", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"ContourPlot", "[", 
      RowBox[{
       RowBox[{"Abs", "[", 
        RowBox[{
         RowBox[{"Conjugate", "[", "Instat1", "]"}], ".", 
         RowBox[{"(", "loopk", ")"}], ".", 
         RowBox[{"Instant4", "[", 
          RowBox[{"x", ",", "y"}], "]"}]}], "]"}], ",", 
       RowBox[{"{", 
        RowBox[{"x", ",", "0", ",", "Pi"}], "}"}], ",", 
       RowBox[{"{", 
        RowBox[{"y", ",", "0", ",", 
         RowBox[{"2", "Pi"}]}], "}"}], ",", 
       RowBox[{"Contours", "\[Rule]", "15"}], ",", 
       RowBox[{"ColorFunction", "\[Rule]", 
        RowBox[{"ColorData", "[", 
         RowBox[{"{", 
          RowBox[{"\"\<SandyTerrain\>\"", ",", 
           RowBox[{"{", 
            RowBox[{"0", ",", "0.6"}], "}"}]}], "}"}], "]"}]}], ",", 
       RowBox[{"ColorFunctionScaling", "\[Rule]", "False"}], ",", 
       RowBox[{"PlotLegends", "\[Rule]", 
        RowBox[{"BarLegend", "[", 
         RowBox[{
          RowBox[{"{", 
           RowBox[{"Automatic", ",", 
            RowBox[{"{", 
             RowBox[{"0", ",", "0.6"}], "}"}]}], "}"}], ",", 
          RowBox[{"{", 
           RowBox[{"Automatic", ",", "20"}], "}"}], ",", 
          RowBox[{"LegendMarkerSize", "\[Rule]", "350"}], ",", 
          RowBox[{"LegendFunction", "\[Rule]", "\"\<Frame\>\""}], ",", 
          RowBox[{"LegendMargins", "\[Rule]", "5"}], ",", 
          RowBox[{"LegendLabel", "\[Rule]", "\"\<Amplitude\>\""}]}], "]"}]}], 
       ",", 
       RowBox[{"FrameLabel", "->", 
        RowBox[{"{", 
         RowBox[{
          RowBox[{"Style", "[", 
           RowBox[{"\"\<\[Phi]\>\"", ",", "Large"}], "]"}], ",", 
          RowBox[{"Style", "[", 
           RowBox[{"\"\<\[CapitalTheta]\>\"", ",", "Large"}], "]"}]}], 
         "}"}]}], ",", 
       RowBox[{"RotateLabel", "\[Rule]", "False"}], ",", 
       RowBox[{"PlotLegends", "\[Rule]", "Automatic"}], ",", 
       RowBox[{"Contours", "\[Rule]", "100"}], ",", 
       RowBox[{"GridLines", "\[Rule]", 
        RowBox[{"{", 
         RowBox[{
          RowBox[{"Range", "[", 
           RowBox[{"0", ",", "Pi", ",", 
            RowBox[{"Pi", "/", "4"}]}], "]"}], ",", " ", 
          RowBox[{"Range", "[", 
           RowBox[{"0", ",", 
            RowBox[{"2", "Pi"}], ",", 
            RowBox[{"Pi", "/", "4"}]}], "]"}]}], "}"}]}], ",", 
       RowBox[{"FrameStyle", "\[Rule]", 
        RowBox[{"Directive", "[", 
         RowBox[{"FontSize", "\[Rule]", "15"}], "]"}]}], ",", 
       RowBox[{"FrameTicks", "\[Rule]", 
        RowBox[{"{", 
         RowBox[{
          RowBox[{"{", 
           RowBox[{
            RowBox[{"{", 
             RowBox[{"0", ",", 
              RowBox[{"Pi", "/", "2"}], ",", "Pi", ",", 
              RowBox[{"3", 
               RowBox[{"Pi", "/", "2"}]}], ",", 
              RowBox[{"2", "Pi"}]}], "}"}], ",", "None"}], "}"}], ",", 
          RowBox[{"{", 
           RowBox[{
            RowBox[{"{", 
             RowBox[{"0", ",", 
              RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], ",", "None"}], 
           "}"}]}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", 
     RowBox[{"FindMaximum", "[", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{
         RowBox[{"Abs", "[", 
          RowBox[{
           RowBox[{"Conjugate", "[", "Instat1", "]"}], ".", 
           RowBox[{"(", "loopk", ")"}], ".", 
           RowBox[{"Instant4", "[", 
            RowBox[{"x1", ",", "y1"}], "]"}]}], "]"}], ",", 
         RowBox[{
          RowBox[{"x1", "\[GreaterEqual]", "0"}], "&&", 
          RowBox[{"y1", "\[GreaterEqual]", "0"}], "&&", 
          RowBox[{"x1", "\[LessEqual]", " ", "Pi"}], "&&", 
          RowBox[{"y1", "\[LessEqual]", 
           RowBox[{"2", "Pi"}]}]}]}], "}"}], ",", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{"x1", ",", 
           RowBox[{"Pi", "/", "2"}]}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{"y1", ",", 
           RowBox[{"Pi", "/", "2"}]}], "}"}]}], "}"}]}], "]"}], ",", 
     "\[IndentingNewLine]", 
     RowBox[{"FindMinimum", "[", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{
         RowBox[{"Abs", "[", 
          RowBox[{
           RowBox[{"Conjugate", "[", "Instat1", "]"}], ".", 
           RowBox[{"(", "loopk", ")"}], ".", 
           RowBox[{"Instant4", "[", 
            RowBox[{"x1", ",", "y1"}], "]"}]}], "]"}], ",", 
         RowBox[{
          RowBox[{"x1", "\[GreaterEqual]", "0"}], "&&", 
          RowBox[{"y1", "\[GreaterEqual]", "0"}], "&&", 
          RowBox[{"x1", "\[LessEqual]", " ", "Pi"}], "&&", 
          RowBox[{"y1", "\[LessEqual]", 
           RowBox[{"2", "Pi"}]}]}]}], "}"}], ",", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{"x1", ",", 
           RowBox[{"Pi", "/", "2"}]}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{"y1", ",", 
           RowBox[{"3", 
            RowBox[{"Pi", "/", "2"}]}]}], "}"}]}], "}"}]}], "]"}]}], "}"}]}], 
  "\[IndentingNewLine]"}]], "Input",
 CellChangeTimes->{
  3.8629028682801523`*^9, {3.862902953304067*^9, 3.8629029767568555`*^9}},
 CellLabel->"In[36]:=",ExpressionUUID->"f612ce7b-1872-4def-99ae-05ab0764a493"],

Cell[BoxData[
 RowBox[{
  RowBox[{"Contourtest4", "[", "loopk_", "]"}], ":=", 
  RowBox[{"{", 
   RowBox[{
    RowBox[{"ContourPlot", "[", 
     RowBox[{
      RowBox[{"Abs", "[", 
       RowBox[{
        RowBox[{"Conjugate", "[", "Instat1", "]"}], ".", 
        RowBox[{"(", "loopk", ")"}], ".", 
        RowBox[{"Instant5", "[", 
         RowBox[{"x", ",", "y"}], "]"}]}], "]"}], ",", 
      RowBox[{"{", 
       RowBox[{"x", ",", "0", ",", "Pi"}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{"y", ",", "0", ",", 
        RowBox[{"2", "Pi"}]}], "}"}], ",", 
      RowBox[{"Contours", "\[Rule]", "15"}], ",", 
      RowBox[{"ColorFunction", "\[Rule]", 
       RowBox[{"ColorData", "[", 
        RowBox[{"{", 
         RowBox[{"\"\<SandyTerrain\>\"", ",", 
          RowBox[{"{", 
           RowBox[{"0", ",", "0.6"}], "}"}]}], "}"}], "]"}]}], ",", 
      RowBox[{"ColorFunctionScaling", "\[Rule]", "False"}], ",", 
      RowBox[{"PlotLegends", "\[Rule]", 
       RowBox[{"BarLegend", "[", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{"Automatic", ",", 
           RowBox[{"{", 
            RowBox[{"0", ",", "0.6"}], "}"}]}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{"Automatic", ",", "20"}], "}"}], ",", 
         RowBox[{"LegendMarkerSize", "\[Rule]", "350"}], ",", 
         RowBox[{"LegendFunction", "\[Rule]", "\"\<Frame\>\""}], ",", 
         RowBox[{"LegendMargins", "\[Rule]", "5"}], ",", 
         RowBox[{"LegendLabel", "\[Rule]", "\"\<Amplitude\>\""}]}], "]"}]}], 
      ",", 
      RowBox[{"FrameLabel", "->", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"Style", "[", 
          RowBox[{"\"\<\[Phi]\>\"", ",", "Large"}], "]"}], ",", 
         RowBox[{"Style", "[", 
          RowBox[{"\"\<\[CapitalTheta]\>\"", ",", "Large"}], "]"}]}], "}"}]}],
       ",", 
      RowBox[{"RotateLabel", "\[Rule]", "False"}], ",", 
      RowBox[{"PlotLegends", "\[Rule]", "Automatic"}], ",", 
      RowBox[{"Contours", "\[Rule]", "100"}], ",", 
      RowBox[{"GridLines", "\[Rule]", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"Range", "[", 
          RowBox[{"0", ",", "Pi", ",", 
           RowBox[{"Pi", "/", "4"}]}], "]"}], ",", " ", 
         RowBox[{"Range", "[", 
          RowBox[{"0", ",", 
           RowBox[{"2", "Pi"}], ",", 
           RowBox[{"Pi", "/", "4"}]}], "]"}]}], "}"}]}], ",", 
      RowBox[{"FrameStyle", "\[Rule]", 
       RowBox[{"Directive", "[", 
        RowBox[{"FontSize", "\[Rule]", "15"}], "]"}]}], ",", 
      RowBox[{"FrameTicks", "\[Rule]", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"0", ",", 
             RowBox[{"Pi", "/", "2"}], ",", "Pi", ",", 
             RowBox[{"3", 
              RowBox[{"Pi", "/", "2"}]}], ",", 
             RowBox[{"2", "Pi"}]}], "}"}], ",", "None"}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"0", ",", 
             RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], ",", "None"}], 
          "}"}]}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", 
    RowBox[{"FindMaximum", "[", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{
        RowBox[{"Abs", "[", 
         RowBox[{
          RowBox[{"Conjugate", "[", "Instat1", "]"}], ".", 
          RowBox[{"(", "loopk", ")"}], ".", 
          RowBox[{"Instant5", "[", 
           RowBox[{"x1", ",", "y1"}], "]"}]}], "]"}], ",", 
        RowBox[{
         RowBox[{"x1", "\[GreaterEqual]", "0"}], "&&", 
         RowBox[{"y1", "\[GreaterEqual]", "0"}], "&&", 
         RowBox[{"x1", "\[LessEqual]", " ", "Pi"}], "&&", 
         RowBox[{"y1", "\[LessEqual]", 
          RowBox[{"2", "Pi"}]}]}]}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"x1", ",", 
          RowBox[{"Pi", "/", "2"}]}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"y1", ",", 
          RowBox[{"Pi", "/", "2"}]}], "}"}]}], "}"}]}], "]"}], ",", 
    "\[IndentingNewLine]", 
    RowBox[{"FindMinimum", "[", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{
        RowBox[{"Abs", "[", 
         RowBox[{
          RowBox[{"Conjugate", "[", 
           RowBox[{"Instat1", ".", 
            RowBox[{"(", "loopk", ")"}]}], "]"}], ".", 
          RowBox[{"Instant5", "[", 
           RowBox[{"x1", ",", "y1"}], "]"}]}], "]"}], ",", 
        RowBox[{
         RowBox[{"x1", "\[GreaterEqual]", "0"}], "&&", 
         RowBox[{"y1", "\[GreaterEqual]", "0"}], "&&", 
         RowBox[{"x1", "\[LessEqual]", " ", "Pi"}], "&&", 
         RowBox[{"y1", "\[LessEqual]", 
          RowBox[{"2", "Pi"}]}]}]}], "}"}], ",", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"x1", ",", 
          RowBox[{"Pi", "/", "2"}]}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"y1", ",", 
          RowBox[{"3", 
           RowBox[{"Pi", "/", "2"}]}]}], "}"}]}], "}"}]}], "]"}]}], 
   "}"}]}]], "Input",
 CellLabel->"In[37]:=",ExpressionUUID->"27a3f66d-101b-4bf6-9607-79fde87ce3f0"],

Cell[BoxData[
 RowBox[{
  RowBox[{"Contourtest5", "[", 
   RowBox[{"loopk_", ",", "J_"}], "]"}], ":=", 
  RowBox[{"Block", "[", 
   RowBox[{
    RowBox[{"{", "\[IndentingNewLine]", 
     RowBox[{"Instat1", ",", "\[IndentingNewLine]", "Instat"}], 
     "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"Instat1", "=", 
      RowBox[{"Flatten", "[", 
       RowBox[{"Table", "[", 
        RowBox[{
         RowBox[{
          RowBox[{
           RowBox[{"F1", "[", 
            RowBox[{
             RowBox[{"Pi", "/", "2"}], ",", 
             RowBox[{"Pi", "/", "2"}]}], "]"}], "[", 
           RowBox[{"[", "x", "]"}], "]"}], "*", 
          RowBox[{"F1", "[", 
           RowBox[{
            RowBox[{"Pi", "/", "2"}], ",", 
            RowBox[{"Pi", "/", "2"}]}], "]"}]}], ",", 
         RowBox[{"{", 
          RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"Instat", "=", 
      RowBox[{"Flatten", "[", 
       RowBox[{"Table", "[", 
        RowBox[{
         RowBox[{
          RowBox[{
           RowBox[{"F1", "[", 
            RowBox[{
             RowBox[{"Pi", "/", "2"}], ",", 
             RowBox[{"Pi", "/", "2"}]}], "]"}], "[", 
           RowBox[{"[", "x", "]"}], "]"}], "*", "Instat1"}], ",", 
         RowBox[{"{", 
          RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"{", 
      RowBox[{
       RowBox[{"ContourPlot", "[", 
        RowBox[{
         RowBox[{"Abs", "[", 
          RowBox[{
           RowBox[{"Conjugate", "[", 
            RowBox[{"P4", "[", 
             RowBox[{"x", ",", "y"}], "]"}], "]"}], ".", 
           RowBox[{"(", 
            RowBox[{"loopk", "/", "J"}], ")"}], ".", "Instat"}], "]"}], ",", 
         RowBox[{"{", 
          RowBox[{"x", ",", "0", ",", "Pi"}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{"y", ",", "0", ",", 
           RowBox[{"2", "Pi"}]}], "}"}], ",", 
         RowBox[{"Contours", "\[Rule]", "15"}], ",", 
         RowBox[{"ColorFunction", "\[Rule]", 
          RowBox[{"ColorData", "[", 
           RowBox[{"{", 
            RowBox[{"\"\<SandyTerrain\>\"", ",", 
             RowBox[{"{", 
              RowBox[{"0", ",", "0.6"}], "}"}]}], "}"}], "]"}]}], ",", 
         RowBox[{"ColorFunctionScaling", "\[Rule]", "False"}], ",", 
         RowBox[{"PlotLegends", "\[Rule]", 
          RowBox[{"BarLegend", "[", 
           RowBox[{
            RowBox[{"{", 
             RowBox[{"Automatic", ",", 
              RowBox[{"{", 
               RowBox[{"0", ",", "0.6"}], "}"}]}], "}"}], ",", 
            RowBox[{"{", 
             RowBox[{"Automatic", ",", "20"}], "}"}], ",", 
            RowBox[{"LegendMarkerSize", "\[Rule]", "350"}], ",", 
            RowBox[{"LegendFunction", "\[Rule]", "\"\<Frame\>\""}], ",", 
            RowBox[{"LegendMargins", "\[Rule]", "5"}], ",", 
            RowBox[{"LegendLabel", "\[Rule]", "\"\<Amplitude\>\""}]}], 
           "]"}]}], ",", 
         RowBox[{"FrameLabel", "->", 
          RowBox[{"{", 
           RowBox[{
            RowBox[{"Style", "[", 
             RowBox[{"\"\<\[Phi]\>\"", ",", "Large"}], "]"}], ",", 
            RowBox[{"Style", "[", 
             RowBox[{"\"\<\[CapitalTheta]\>\"", ",", "Large"}], "]"}]}], 
           "}"}]}], ",", 
         RowBox[{"RotateLabel", "\[Rule]", "False"}], ",", 
         RowBox[{"PlotLegends", "\[Rule]", "Automatic"}], ",", 
         RowBox[{"Contours", "\[Rule]", "100"}], ",", 
         RowBox[{"GridLines", "\[Rule]", 
          RowBox[{"{", 
           RowBox[{
            RowBox[{"Range", "[", 
             RowBox[{"0", ",", "Pi", ",", 
              RowBox[{"Pi", "/", "4"}]}], "]"}], ",", " ", 
            RowBox[{"Range", "[", 
             RowBox[{"0", ",", 
              RowBox[{"2", "Pi"}], ",", 
              RowBox[{"Pi", "/", "4"}]}], "]"}]}], "}"}]}], ",", 
         RowBox[{"FrameStyle", "\[Rule]", 
          RowBox[{"Directive", "[", 
           RowBox[{"FontSize", "\[Rule]", "15"}], "]"}]}], ",", 
         RowBox[{"FrameTicks", "\[Rule]", 
          RowBox[{"{", 
           RowBox[{
            RowBox[{"{", 
             RowBox[{
              RowBox[{"{", 
               RowBox[{"0", ",", 
                RowBox[{"Pi", "/", "2"}], ",", "Pi", ",", 
                RowBox[{"3", 
                 RowBox[{"Pi", "/", "2"}]}], ",", 
                RowBox[{"2", "Pi"}]}], "}"}], ",", "None"}], "}"}], ",", 
            RowBox[{"{", 
             RowBox[{
              RowBox[{"{", 
               RowBox[{"0", ",", 
                RowBox[{"Pi", "/", "2"}], ",", "Pi"}], "}"}], ",", "None"}], 
             "}"}]}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", 
       RowBox[{"FindMaximum", "[", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{
           RowBox[{"Abs", "[", 
            RowBox[{
             RowBox[{"Conjugate", "[", 
              RowBox[{
               RowBox[{"P4", "[", 
                RowBox[{"x1", ",", "y1"}], "]"}], ".", 
               RowBox[{"(", 
                RowBox[{"loopk", "/", "J"}], ")"}]}], "]"}], ".", "Instat"}], 
            "]"}], ",", 
           RowBox[{
            RowBox[{"x1", "\[GreaterEqual]", "0"}], "&&", 
            RowBox[{"y1", "\[GreaterEqual]", "0"}], "&&", 
            RowBox[{"x1", "\[LessEqual]", " ", "Pi"}], "&&", 
            RowBox[{"y1", "\[LessEqual]", 
             RowBox[{"2", "Pi"}]}]}]}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"x1", ",", 
             RowBox[{"Pi", "/", "2"}]}], "}"}], ",", 
           RowBox[{"{", 
            RowBox[{"y1", ",", 
             RowBox[{"3", 
              RowBox[{"Pi", "/", "2"}]}]}], "}"}]}], "}"}]}], "]"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{"FindMinimum", "[", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{
           RowBox[{"Abs", "[", 
            RowBox[{
             RowBox[{"Conjugate", "[", 
              RowBox[{
               RowBox[{"P4", "[", 
                RowBox[{"x1", ",", "y1"}], "]"}], ".", 
               RowBox[{"(", 
                RowBox[{"loopk", "/", "J"}], ")"}]}], "]"}], ".", "Instat"}], 
            "]"}], ",", 
           RowBox[{
            RowBox[{"x1", "\[GreaterEqual]", "0"}], "&&", 
            RowBox[{"y1", "\[GreaterEqual]", "0"}], "&&", 
            RowBox[{"x1", "\[LessEqual]", " ", "Pi"}], "&&", 
            RowBox[{"y1", "\[LessEqual]", 
             RowBox[{"2", "Pi"}]}]}]}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"x1", ",", 
             RowBox[{"Pi", "/", "2"}]}], "}"}], ",", 
           RowBox[{"{", 
            RowBox[{"y1", ",", 
             RowBox[{"Pi", "/", "2"}]}], "}"}]}], "}"}]}], "]"}]}], 
      "\[IndentingNewLine]", "}"}]}]}], "\[IndentingNewLine]", 
   "]"}]}]], "Input",
 CellLabel->"In[38]:=",ExpressionUUID->"d00915e6-818e-4348-a84f-ebc58a769b80"],

Cell[BoxData[
 RowBox[{
  RowBox[{"BS", "[", 
   RowBox[{"st1_", ",", "st2_", ",", "c_"}], "]"}], ":=", 
  RowBox[{"Block", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"Instat3", ",", "Instat2"}], "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"Instat2", "=", 
      RowBox[{"Flatten", "[", 
       RowBox[{"Table", "[", 
        RowBox[{
         RowBox[{
          RowBox[{
           RowBox[{"F1", "[", 
            RowBox[{"st1", ",", "st2"}], "]"}], "[", 
           RowBox[{"[", "x", "]"}], "]"}], "*", 
          RowBox[{"F1", "[", 
           RowBox[{"st1", ",", "st2"}], "]"}]}], ",", 
         RowBox[{"{", 
          RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"Instat3", "=", 
      RowBox[{"Flatten", "[", 
       RowBox[{"Table", "[", 
        RowBox[{
         RowBox[{
          RowBox[{
           RowBox[{"F1", "[", 
            RowBox[{"st1", ",", "st2"}], "]"}], "[", 
           RowBox[{"[", "x", "]"}], "]"}], "*", "Instat2"}], ",", 
         RowBox[{"{", 
          RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"c2", "=", 
      RowBox[{"Abs", "[", 
       RowBox[{
        RowBox[{"Conjugate", "[", 
         RowBox[{"P2", "[", 
          RowBox[{"st1", ",", 
           RowBox[{"st2", "+", "Pi"}]}], "]"}], "]"}], ".", 
        RowBox[{"(", 
         RowBox[{"tests", "[", "c", "]"}], ")"}], ".", "Instat3"}], "]"}]}], 
     ";", "\[IndentingNewLine]", "c2"}]}], "\[IndentingNewLine]", 
   "]"}]}]], "Input",
 CellLabel->"In[39]:=",ExpressionUUID->"182da53a-0eb5-4be3-b517-fac8f40e39b3"],

Cell[BoxData[
 RowBox[{
  RowBox[{"BSS", "[", 
   RowBox[{"st1_", ",", "st2_", ",", "c_"}], "]"}], ":=", 
  RowBox[{"Block", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"Instat3", ",", "Instat2"}], "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"Instat2", "=", 
      RowBox[{"Flatten", "[", 
       RowBox[{"Table", "[", 
        RowBox[{
         RowBox[{
          RowBox[{
           RowBox[{"F1", "[", 
            RowBox[{"st1", ",", "st2"}], "]"}], "[", 
           RowBox[{"[", "x", "]"}], "]"}], "*", 
          RowBox[{"F1", "[", 
           RowBox[{"st1", ",", "st2"}], "]"}]}], ",", 
         RowBox[{"{", 
          RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"Instat3", "=", 
      RowBox[{"Flatten", "[", 
       RowBox[{"Table", "[", 
        RowBox[{
         RowBox[{
          RowBox[{
           RowBox[{"F1", "[", 
            RowBox[{"st1", ",", "st2"}], "]"}], "[", 
           RowBox[{"[", "x", "]"}], "]"}], "*", "Instat2"}], ",", 
         RowBox[{"{", 
          RowBox[{"x", ",", "1", ",", "2"}], "}"}]}], "]"}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"c2", "=", 
      RowBox[{"Abs", "[", 
       RowBox[{
        RowBox[{"Conjugate", "[", 
         RowBox[{"P2", "[", 
          RowBox[{"st1", ",", 
           RowBox[{"st2", "+", "Pi"}]}], "]"}], "]"}], ".", 
        RowBox[{"(", 
         RowBox[{"testp", "[", "c", "]"}], ")"}], ".", "Instat3"}], "]"}]}], 
     ";", "\[IndentingNewLine]", "c2"}]}], "\[IndentingNewLine]", 
   "]"}]}]], "Input",
 CellLabel->"In[40]:=",ExpressionUUID->"6efe69b3-503f-4608-93bc-97fa594a4d97"],

Cell[BoxData[
 RowBox[{
  RowBox[{"DumpSave", "[", 
   RowBox[{"\"\<TotFunc.mx\>\"", ",", 
    RowBox[{"{", 
     RowBox[{
     "Unitarization", ",", "F1", ",", "P1", ",", "P2", ",", "P3", ",", "P4", 
      ",", "Instant", ",", "Instat1", ",", "Instat2", ",", "Instat3", ",", 
      "Instant4", ",", "Instant5", ",", "Contourtest", ",", "Contourtest2", 
      ",", "Contourtest3", ",", "Contourtest4", ",", "Contourtest5", ",", 
      "BS", ",", "BSS"}], "}"}]}], "]"}], ";"}]], "Input",
 CellChangeTimes->{{3.851754799991646*^9, 3.851754885837947*^9}, {
  3.8517557902851877`*^9, 3.8517557921657567`*^9}, {3.8518330846007385`*^9, 
  3.851833086566785*^9}, {3.85183317985536*^9, 3.851833183148368*^9}, {
  3.851833486512679*^9, 3.851833486870114*^9}, {3.8518469469740825`*^9, 
  3.851846947988594*^9}, {3.86290302987985*^9, 3.8629030659260263`*^9}, {
  3.862905205231229*^9, 3.862905260320223*^9}, {3.862905332850164*^9, 
  3.862905334407528*^9}},
 CellLabel->"In[41]:=",ExpressionUUID->"74c6620d-bf45-40ee-b455-f145f4426a7c"]
},
WindowSize->{798, 967},
WindowMargins->{{Automatic, -7}, {Automatic, 0}},
FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (2019\:5e744\:67088\
\:65e5)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 220, 3, 45, "Input",ExpressionUUID->"6814b69d-8fee-4b41-9bc4-e7c2489429c8"],
Cell[CellGroupData[{
Cell[803, 27, 253, 4, 45, "Input",ExpressionUUID->"64aafcbe-cf03-4ab2-ba0a-3e637cc7e450"],
Cell[1059, 33, 1127, 16, 32, "Output",ExpressionUUID->"23e4677b-24be-4d4a-a69e-4738ba474037"]
}, Open  ]],
Cell[2201, 52, 4730, 127, 716, "Input",ExpressionUUID->"8fc10523-3fdb-442c-bdee-c18c75a3e2b0"],
Cell[6934, 181, 621, 18, 45, "Input",ExpressionUUID->"dda2564d-b9b3-480a-bbc7-4a2d75d0a1c5"],
Cell[7558, 201, 646, 19, 45, "Input",ExpressionUUID->"d350f6dc-dea1-43c6-86d7-a7bfc3331caa"],
Cell[8207, 222, 711, 22, 45, "Input",ExpressionUUID->"29aa4b86-7d5c-4e88-9ce5-9739ee71a7c5"],
Cell[8921, 246, 653, 20, 45, "Input",ExpressionUUID->"e9382540-8936-4a17-8098-0168a221185d"],
Cell[9577, 268, 1298, 40, 82, "Input",ExpressionUUID->"cbbc6a14-6179-4733-9593-34b1871680c6"],
Cell[10878, 310, 1121, 35, 82, "Input",ExpressionUUID->"c0a69fe8-9e94-4b05-9eee-3404b29bb04b"],
Cell[12002, 347, 8069, 194, 697, "Input",ExpressionUUID->"fc1813e4-6d99-41a8-a1cc-919b81c5a1c8"],
Cell[20074, 543, 4988, 132, 508, "Input",ExpressionUUID->"973d8df8-bc65-4995-aa75-c3864a5e86c3"],
Cell[25065, 677, 5252, 135, 529, "Input",ExpressionUUID->"f612ce7b-1872-4def-99ae-05ab0764a493"],
Cell[30320, 814, 5015, 133, 508, "Input",ExpressionUUID->"27a3f66d-101b-4bf6-9607-79fde87ce3f0"],
Cell[35338, 949, 6976, 179, 697, "Input",ExpressionUUID->"d00915e6-818e-4348-a84f-ebc58a769b80"],
Cell[42317, 1130, 1659, 46, 196, "Input",ExpressionUUID->"182da53a-0eb5-4be3-b517-fac8f40e39b3"],
Cell[43979, 1178, 1660, 46, 196, "Input",ExpressionUUID->"6efe69b3-503f-4608-93bc-97fa594a4d97"],
Cell[45642, 1226, 1026, 18, 141, "Input",ExpressionUUID->"74c6620d-bf45-40ee-b455-f145f4426a7c"]
}
]
*)

